<%@ page 
          import="com.softplus.carrefour.hd.bltier.pc.ICaseHeadViewer,
                         com.softplus.carrefour.hd.bltier.pc.CCaseHeadManage,
                         com.softplus.carrefour.hd.CFHDSystem,
                         com.softplus.carrefour.CFException,
                         com.softplus.carrefour.hd.bltier.entity.UserAccount"
%>
<html>
<head>
<title>auto escalated</title>
</head>
<%
                              System.out.println(" * * * * * auto escalated 02 \n  * * * * *  AUTO ESCALATE COUNTER");
                         
     UserAccount      userVO            =    (UserAccount) session.getAttribute("userVO");
      String                   userid             =    userVO.getUserId();
      String          viewcasesURL      =    "/CFHD/servlet/com.softplus.carrefour.hd.frontend.servlet.process.CFHDPC01"; 
      String                  parentObj        =   request.getParameter("updmodal")!=null?"parent.parent":"parent"; //from update modal ?

                               System.out.println(" * * * * * parentObj **]"+parentObj+"[");
%>
<script src="../script/Alert.js" type="text/javascript"></script>
<script type="text/javascript">
<!--
    var timepopescalate =0;
    
     function confirmEscalate(){
          var okSaveButton = " OK ";
          var cancelSaveButton =" cancel ";
          
          try{
                       window.clearInterval(timepopescalate);
                         //<%= parentObj %>.all.programLayer.style.visibility='hidden';
                         //<%= parentObj %>.all.processingLayer.style.visibility='visible';
                       <%= parentObj %>.frm.checkUnload.value = "autoescalted";
                       <%= parentObj %>.parent.logout.onclick=parent.parent.whenLogout;
                       
          }catch(error){ 
          //alert('error'+error)
          }   
          
           if(showOInfoDialog("Auto escalated", "The case escalate automatically.\n click OK  to continue.", okSaveButton )){
               <%= parentObj %>.location = '<%= viewcasesURL %>';
           }
     }
     
     function popAuto(poptime){
          window.setInterval("confirmEscalate",poptime)
     }
-->
</script>
<body>
<button onclick="Javascript:parent.closeUpdateWin()">close modalUpdate</button>
<%

      String   caseid4Ae = request.getParameter("caseID") == null ? "none" : request.getParameter("caseID");
      long   remainTime = 0;
      int   timeTicker = 0;
      
      if(!caseid4Ae.equalsIgnoreCase("none")){
//                               System.out.println(" * * * * * caseid4Ae "+caseid4Ae);

                ICaseHeadViewer  headManage  = (CCaseHeadManage) CFHDSystem.getControlClass("CASE_HEAD");
//                System.out.println(" * * * * * headManage "+headManage);
                
                                                  remainTime   =  headManage.getCountingTime(caseid4Ae,userid);  //userid from MT07

                System.out.println(" * * * * * remainTime "+remainTime);

                
				if(remainTime>0){ //if reamainTime not equals -1, means no auto escalated

//                        remainTime = 10000;  // *** for test

//                         out.println(" * * * * * Time Left :>"+remainTime/1000+" sec.");
//                         long warningPeriod = 60000; //60000 // 1 minutes.
                         
                         out.println(" <script type=\"text/javascript\">");
//                         out.println(" timetick ="+remainTime+";");
//                         out.println("  window.clearInterval(timepopescalate); ");
                         if(request.getParameter("updmodal")!=null){
                              out.println("  parent.timepopescalate = parent.setInterval(confirmEscalate,"+(remainTime-3000)+"); "); // triged 3 sec before the real time
                        }else{
                              out.println("  timepopescalate = window.setInterval(confirmEscalate,"+(remainTime-3000)+"); "); // triged 3 sec before the real time
                        }
                         out.println("</script>");
				} //END if reamainTime not equals -1, means no auto escalated
     }
                              
%>

</body>
</html>
